// pages/nav/nav.js
var app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    userInfo: Object,
    tab: String,
    isIphoneX: {
      type: 'boolen',
      default: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
  
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goCenter: function(e) {
      var pages = getCurrentPages() //获取加载的页面
      var currentPage = pages[pages.length - 1] //获取当前页面的对象
      var url = currentPage.route //当前页面url
      var targetPage = e.currentTarget.dataset.url.substring(1)
      if (url != targetPage) {
        wx.navigateTo({
          url: '/' + targetPage
        })
      }
    },
    goIndex: function (e) {
      var pages = getCurrentPages() //获取加载的页面
      var currentPage = pages[pages.length - 1] //获取当前页面的对象
      var url = currentPage.route //当前页面url
      var targetPage = e.currentTarget.dataset.url.substring(1)
      if (url != targetPage) {
        wx.navigateBack({
          delta: 100
        })
      }
    },
    getUser: function (r) {
      var _this = this
      if (r.detail.errMsg == 'getUserInfo:ok') {
        app.globalData.userInfo = r.detail.userInfo
        wx.request({
          url: app.globalData.url+'/v1/wechat/user',
          method: 'POST',
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            nikname: r.detail.userInfo.nickName,
            headimgurl: r.detail.userInfo.avatarUrl,
            openid: app.globalData.openId
          },
          success: function (r) {
            if (r.data.code == 0) {
              wx.navigateTo({
                url: '/pages/center/center',
              })
            }
          }
        })
      }
    }
  },

})
